<template>
  <edit-layout ref="layout" :page="page" :form="form" @invoke="invoke">
    <el-form
      ref="form"
      :model="form"
      :size="page.settings.formSize"
      :label-width="page.settings.labelWidth"
    >
      <el-form-item label="编码" prop="no" :rules="page.rules.def">
        <el-input v-model="form.no" class="col" placeholder="请输入编码" />
      </el-form-item>
      <el-form-item label="名称" prop="name" :rules="page.rules.def">
        <el-input v-model="form.name" class="col" placeholder="请输入名称" />
      </el-form-item>
      <el-form-item v-if="form.id" label="状态" prop="used">
        <el-tag v-if="form.used=='Y'" type="success">已启用</el-tag>
        <el-tag v-else-if="form.used=='N'" type="danger">未启用</el-tag>
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input v-model="form.sort" class="col" placeholder="排序" />
      </el-form-item>
    </el-form>
  </edit-layout>
</template>
<script>
import adminSupport from 'lola-admin-support-el'

export default {
  name: 'CostClassEdit',
  mixins: [adminSupport.mixins.edit],
  data() {
    return {
      name: 'CostClass'
    }
  },
  mounted() {
    this.page.tip = ''
    this.init() // 初始化
  },
  methods: {
    init() {
      const that = this
      that.page.ids.push(this.$route.params.no) // 页面主参数赋值
      that.loadData() // 加载数据
    },
    appendForm() {
      const roleIds = []
      if (this.form.roles != null) {
        this.form.roles.forEach(item => {
          roleIds.push(item.id)
        })
      }
      this.form.roleIds = roleIds
    },
    buildForm() {
      return true
    }
  }
}
</script>
